package Ex1;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class Ex7 {
    public static void main(String[] args) {
        /**项目描述：
         共计21张牌。在{村民，狼人，守护，预言家，猎人，丘比特，长老，盗贼，替罪羊，女巫}随机生成12-18个身份
         (每个身份唯一，村民狼人除外)。有三张底牌，底牌必须不能出现盗贼身份。
         玩家输入游戏人数：15
         随机生成游戏人数配置：
         游戏配置：12-18人（大于18人或者小于12人，输出超出游戏人数范围）
         标准配置：
         人数（狼，民，神）
         18（5,7,5）人    5狼人     7村民        1预言家 1女巫   1丘比特 1守护 1猎人 1村长 1 替罪羊 1吹笛者 1盗贼      21张牌
         17（5,6,6）人    5狼人     7村民        1预言家 1女巫   1丘比特 1守护 1猎人 1村长 1 替罪羊 1盗贼                    20张牌
         16（5,6,5）人    5狼人     6村民        1预言家 1女巫   1丘比特 1守护 1猎人 1村长 1 替罪羊 1盗贼                    19张牌
         15（5,5,5）人    5狼人     5村民        1预言家 1女巫   1丘比特 1守护 1猎人 1村长 1 替罪羊 1盗贼                    18张牌
         14（4,5,5）人    4狼人     5村民        1预言家 1女巫   1丘比特 1守护 1猎人 1村长 1 替罪羊1 盗贼                    17张牌
         13（4,5,4）人    4狼人     5村民        1预言家 1女巫   1丘比特 1守护 1猎人 1村长 1 盗贼		                     16张牌
         12（4,4,4）人    4狼人     4村民        1预言家 1女巫   1丘比特 1守护 1猎人 1村长 1 盗贼		                     15张牌

         盗贼是一个特殊身份：当某位玩家获得盗贼牌的时候，可以翻开底牌三张选择底牌中自己想要的身份（有狼人要选狼人）
         要求：
         1.底牌可以没有狼人，如果有，最多只能有一个狼人；
         2.底牌不能有盗贼；
         3.输出如下：
         玩家手牌为：
         {01：村民，02：丘比特，03：盗贼，...  ，15：女巫}
         盗贼底牌为：
         {01：XX，02:XX ，03:XX}*/
        //随机生成器
        Random a = new Random();
        //int num = a.nextInt(12+1) + 6;
        //System.out.println(num);
        String[] downCard = new String[3];
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入游戏人数");
        int b = sc.nextInt();
        if (12 > b || b > 18) {
            System.out.println("请输入正确的玩家人数");
        } else if (b == 12) {
            String[] c = {"狼人1", "平民1", "平民2", "平民3", "平民4", "预言家", "女巫", "丘比特", "守护", "猎人", "村长"};
            //只留一个狼人与除盗贼以外的神民，平民洗牌.1狼人，4村民，1预言家，1女巫，1丘比特 1守护 1猎人 1村长 (11人)
            for (int i = 0; i < 21; i++) {
                int ca = a.nextInt(11);
                String d = c[ca];
                c[ca] = c[0];
                c[0] = d;

            }
            for (int i = 0; i <= 2; i++) {
                downCard[i] = c[c.length - 1 - i];
            }
            //从11中选8个与3个狼人，盗贼进行洗牌
            String[] e = new String[c.length - 3];
            System.arraycopy(c, 0, e, 0, c.length - 3);

            e = Arrays.copyOf(e, e.length + 4);
            e[e.length - 1] = "盗贼";
            e[e.length - 2] = "狼人2";
            e[e.length - 3] = "狼人3";
            e[e.length - 4] = "狼人4";

            for (int i = 0; i < 25; i++) {
                int ea = a.nextInt(12);
                String d = e[ea];
                e[ea] = e[0];
                e[0] = d;


            }
            for (int i = 0; i <= 11; i++) {
                System.out.println("0" + (i + 1) + ":" + e[i] + "");
            }
            System.out.println("盗贼底牌为：" + "\t");
            for (int i = 0; i < 3; i++) {
                System.out.println("0" + (i + 1) + ":" + downCard[i] + "");
            }

        } else if (b == 13) {
            String[] c = {"狼人1", "平民1", "平民2", "平民3", "平民4", "平民5", "预言家", "女巫", "丘比特", "守护", "猎人", "村长"};
            //只留一个狼人与除盗贼以外的神民，平民洗牌.1狼人，5村民，1预言家，1女巫，1丘比特 1守护 1猎人 1村长(12人)
            for (int i = 0; i < 23; i++) {
                int ca = a.nextInt(12);
                String d = c[ca];
                c[ca] = c[0];
                c[0] = d;

            }
            for (int i = 0; i <= 2; i++) {
                downCard[i] = c[c.length - 1 - i];
            }
            //从11中选8个与3个狼人，盗贼进行洗牌
            String[] e = new String[c.length - 3];
            System.arraycopy(c, 0, e, 0, c.length - 3);

            e = Arrays.copyOf(e, e.length + 4);
            e[e.length - 1] = "盗贼";
            e[e.length - 2] = "狼人2";
            e[e.length - 3] = "狼人3";
            e[e.length - 4] = "狼人4";

            for (int i = 0; i < 25; i++) {
                int ea = a.nextInt(13);
                String d = e[ea];
                e[ea] = e[0];
                e[0] = d;


            }
            for (int i = 0; i <= 12; i++) {
                System.out.println("0" + (i + 1) + ":" + e[i] + "");
            }

            System.out.println("盗贼底牌为：" + "\t");
            for (int i = 0; i < 3; i++) {
                System.out.println("0" + (i + 1) + ":" + downCard[i] + "");
            }

        }else if(b == 14){
            String[] c = {"狼人1","平民1","平民2","平民3","平民4","平民5","预言家","女巫","丘比特","守护","猎人","村长","替罪羊",};
            //1狼人     5村民        1预言家 1女巫   1丘比特 1守护 1猎人 1村长 1 替罪羊 进行洗牌
            for (int i = 0;i < 50;i ++){
                int ca = a.nextInt(13);
                String d = c[ca];
                c[ca] = c[0];
                c[0] = d;
            }
            for(int i = 0;i <= 2;i ++){
                downCard[i] = c[c.length - 1 - i];
            }//从洗牌之后的最后三张输出三张底牌
            c = Arrays.copyOf(c,c.length+1);
            c[c.length - 1] = "狼人2";
            c[c.length - 2] = "狼人3";
            c[c.length - 3] = "狼人4";
            c[c.length - 4] = "盗贼";
            for(int i = 0;i <= 50;i ++){
                int ca = a.nextInt(14);
                String d = c[ca];
                c[ca] = c[0];
                c[0] = d;
            }
            for(int i = 0;i <= 13;i ++){
                System.out.println("0" + (i + 1) + ":" + c[i] + "");
            }
            System.out.println("盗贼的底牌为：" + "\t");
            for(int i = 0;i <= 2;i ++){
                System.out.println("0" + (i + 1) + ":" +downCard[i] + "");
            }
        } else if(b == 15){
            String[] c = {"狼人1","平民1","平民2","平民3","平民4","平民5","预言家","女巫","丘比特","守护","猎人","村长","替罪羊"};
            //5狼人     5村民        1预言家 1女巫   1丘比特 1守护 1猎人 1村长 1 替罪羊 1盗贼
            for(int i =0;i < 50;i ++){
                int ca = a.nextInt(13);
                String d = c[ca];
                c[ca] = c[0];
                c[0] = d;
            }
            for(int i = 0;i <= 2;i++){
                downCard[i] = c[c.length - 1 - i];
            }
            c = Arrays.copyOf(c,c.length + 2);
            c[c.length - 1] = "狼人2";
            c[c.length - 2] = "狼人3";
            c[c.length - 3] = "狼人4";
            c[c.length - 4] = "狼人5";
            c[c.length - 5] = "盗贼";
            for(int i = 0;i < 50;i ++){
                int ca = a.nextInt(15);
                String d = c[ca];
                c[ca] = c[0];
                c[0] = d;
            }
            for(int i = 0;i < 15;i ++){
                System.out.println("0" + (i+1) + ":" + c[i] + "");
            }
            System.out.println("盗贼的底牌为：" + "/t");
            for(int i = 0;i <= 2;i ++){
                System.out.println("0" + (i+1) + downCard[i] + "");
            }
        }else if(b == 16){
            String[] c = {"狼人1","平民1","平民2","平民3","平民4","平民5","平民6","预言家","女巫","丘比特",
                    "守护","猎人","村长","替罪羊"};
            //5狼人     6村民        1预言家 1女巫   1丘比特 1守护 1猎人 1村长 1 替罪羊 1盗贼
            for(int i =0;i < 50;i ++){
                int ca = a.nextInt(14);
                String d = c[ca];
                c[ca] = c[0];
                c[0] = d;
            }
            for(int i = 0;i <= 2;i++){
                downCard[i] = c[c.length - 1 - i];
            }
            c = Arrays.copyOf(c,c.length + 2);
            c[c.length - 1] = "狼人2";
            c[c.length - 2] = "狼人3";
            c[c.length - 3] = "狼人4";
            c[c.length - 4] = "狼人5";
            c[c.length - 5] = "盗贼";
            for(int i = 0;i < 50;i ++){
                int ca = a.nextInt(16);
                String d = c[ca];
                c[ca] = c[0];
                c[0] = d;
            }
            for(int i = 0;i < 16;i ++){
                System.out.println("0" + (i+1) + ":" + c[i] + "");
            }
            System.out.println("盗贼的底牌为：" + "/t");
            for(int i = 0;i <= 2;i ++){
                System.out.println("0" + (i+1) + downCard[i] + "");
            }
        }else if(b == 17){
            String[] c = {"狼人1","平民1","平民2","平民3","平民4","平民5","平民6","平民7","预言家","女巫","丘比特",
                    "守护","猎人","村长","替罪羊"};
            //5狼人     7村民        1预言家 1女巫   1丘比特 1守护 1猎人 1村长 1 替罪羊 1盗贼
            for(int i =0;i < 50;i ++){
                int ca = a.nextInt(15);
                String d = c[ca];
                c[ca] = c[0];
                c[0] = d;
            }
            for(int i = 0;i <= 2;i++){
                downCard[i] = c[c.length - 1 - i];
            }
            c = Arrays.copyOf(c,c.length + 2);
            c[c.length - 1] = "狼人2";
            c[c.length - 2] = "狼人3";
            c[c.length - 3] = "狼人4";
            c[c.length - 4] = "狼人5";
            c[c.length - 5] = "盗贼";
            for(int i = 0;i < 50;i ++){
                int ca = a.nextInt(17);
                String d = c[ca];
                c[ca] = c[0];
                c[0] = d;
            }
            for(int i = 0;i < 17;i ++){
                System.out.println("0" + (i+1) + ":" + c[i] + "");
            }
            System.out.println("盗贼的底牌为：" + "/t");
            for(int i = 0;i <= 2;i ++){
                System.out.println("0" + (i+1) + downCard[i] + "");
            }
        }else if(b == 18){
            String[] c = {"狼人1","平民1","平民2","平民3","平民4","平民5","平民6","平民7","预言家","女巫","丘比特","守护",
                    "猎人","村长","替罪羊","吹笛者"};
            //5狼人     7村民        1预言家 1女巫   1丘比特 1守护 1猎人 1村长 1 替罪羊 1吹笛者 1盗贼
            for(int i =0;i < 50;i ++){
                int ca = a.nextInt(16);
                String d = c[ca];
                c[ca] = c[0];
                c[0] = d;
            }
            for(int i = 0;i <= 2;i++){
                downCard[i] = c[c.length - 1 - i];
            }
            c = Arrays.copyOf(c,c.length + 2);
            c[c.length - 1] = "狼人2";
            c[c.length - 2] = "狼人3";
            c[c.length - 3] = "狼人4";
            c[c.length - 4] = "狼人5";
            c[c.length - 5] = "盗贼";
            for(int i = 0;i < 50;i ++){
                int ca = a.nextInt(18);
                String d = c[ca];
                c[ca] = c[0];
                c[0] = d;
            }
            for(int i = 0;i < 18;i ++){
                System.out.println("0" + (i+1) + ":" + c[i] + "");
            }
            System.out.println("盗贼的底牌为：" + "/t");
            for(int i = 0;i <= 2;i ++){
                System.out.println("0" + (i+1) + downCard[i] + "");
            }
        }
    }
}
